<?php get_header(); ?>
<!-- COUNT RESULTS -->
<?php
/* Search Count */
$allsearch = &new WP_Query("s=$s&showposts=-1");
$key = wp_specialchars($s, 1);
$count = $allsearch->post_count;
wp_reset_query();
?>

<!-- / COUNT RESULTS -->
<section class="content">
    <ul id="products" class="list clearfix">
        <?php if (have_posts()) : ?>
            <?php
            while (have_posts()) : the_post();
                $anh = wpsc_the_product_image();
                $date = get_the_date('d-M-Y');
                $array_date = explode('-', $date);
                $meta_value = get_post_custom_values('video', get_the_ID());
                $post_type_search = get_post_type(wpsc_the_product_id());
                if ($post_type_search == 'wpsc-product') {
                    ?>
                    <?php $guid_pro = $wpdb->get_row("select guid from wp_posts where ID=" . wpsc_the_product_id()); ?>
                    <!-- LIST RESULTS -->
                    <li class="da-thumbs">
                        <div class="product-thumb-hover">
                            <section class="left"><a href="<?php echo $guid_pro->guid; ?>"> <img src="<?php echo wpsc_the_product_thumbnail(); ?>" alt="">
                                </a>                            </section>
                        </div>
                        <section class="center">
                            <h3><?php echo wpsc_the_product_title(); ?></h3>
                            <em>Loai: <a href="#">

                                    <?php
// lấy ra các category  của sản phẩm duyệt  và lấy các name của category		    
                                    $terms = get_the_terms($post->ID, 'wpsc_product_category');
                                    if ($terms && !is_wp_error($terms)) :
                                        $categories = array();
                                        foreach ($terms as $term) {
                                            echo $categories = $term->name;
                                            echo " ";
                                        }
                                        //	echo $categories[0];				
                                        ?>

                                    <?php endif; ?>
                                    <form class="product_form"   enctype="multipart/form-data" action="<?php echo get_page_link(31); ?>" 
                                          method="post" name="product_<?php echo wpsc_the_product_id(); ?>" 
                                          id="product_<?php echo wpsc_the_product_id(); ?>" >
                                        <input type="hidden" value="add_to_cart" name="wpsc_ajax_action"/>
                                        <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id"/>
                                        <input type="submit"  value="<?php _e('Add To Cart', 'wpsc'); ?>" name="Buy" 
                                               class="wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button"/>
                                    </form>
                                </a></em> </section>
                        <section class="right"> <span class="price"><small>
                                    <?php
                                    if (wpsc_product_normal_price() == "$0.00") {
                                        echo "";
                                    } else {
                                        echo wpsc_product_normal_price();
                                    }
                                    ?>
                                </small> giảm còn&nbsp;&nbsp;<?php echo wpsc_the_product_price(); ?></span>
                            <ul class="menu-button">
                                <li>
                                    <a  value="product_<?php echo wpsc_the_product_id(); ?>_submit_button" 
                                        class="cart tip" onclick="return click_addtocart(<?php echo wpsc_the_product_id(); ?>);" 
                                        href="JavaScript:void(0);" title="Mua Hàng"></a>
                                </li>

                                <li><a href="<?php echo $guid_pro->guid; ?>" 
                                       class="link tip" title="Chi Tiết"></a>
                                </li>
                            </ul>
                        </section>


                    </li>
                    <!-- / LIST RESULTS -->

                    <?php
                } else {
                    if ($meta_value[0] == '') {
                        ?>

                        <!--entry-->
                        <?php
                        //kết thúc tại đây 
                    } else {
                        ?>
                        <div class="entry">
                            <div class="meta">
                                <span><small class="post-video"></small>
                                    <strong><?php echo $array_date[0]; ?></strong>
                                    <small><?php echo $array_date[1] . "</br>" . $array_date[2]; ?></small>
                                </span> 
                            </div>
                            <div class="video-container"> <?php echo $meta_value[0]; ?> </div>
                            <h2><a href="single.html"><?php the_title(); ?></a></h2>
                            <ul>
                                <li class="post">Posted by: <a href="#"><?php the_author(); ?></a></li>
                                <li class="category">Loại: <a href="#"><?php the_category(', ') ?></a></li>
                                <li class="comment">Comment: <a href="#"><?php comments_number('0', '1', '%'); ?></a></li>
                            </ul>
                            <p><?php the_excerpt(); ?></p>
                            <span><a href="single.html">Learn more</a></span>
                        </div>
                        <?php
                    }
                }
            endwhile;
        else:
            ?>
        </ul>


<?php endif; ?>
</section>


<?php get_sidebar(); ?>
<?php get_footer(); ?>
